#include "mycanvasyx.h"
#include <qpainter.h>
MyCanvasYX::MyCanvasYX(QWidget *parent) : MyCanvas(parent)
{

}

void MyCanvasYX::pintarFuncion()
{
    QPainter pincel(this);
    pincel.setPen(Qt::blue);
    for(int i=0;i<this->funcion->puntos->elementos->size()-1;i++)
    {
        if(this->funcion->puntos->elementos->at(i).x!=NULL && this->funcion->puntos->elementos->at(i+1).x!=NULL)
        {
            double x1=this->funcion->puntos->elementos->at(i).x;
            double x2=this->funcion->puntos->elementos->at(i+1).x;
            double y1=this->funcion->puntos->elementos->at(i).y;
            double y2=this->funcion->puntos->elementos->at(i+1).y;
            int nx1=this->x_canvas(x1, &this->size());
            int nx2=this->x_canvas(x2, &this->size());
            int ny1=this->y_canvas(y1, &this->size());
            int ny2=this->y_canvas(y2, &this->size());
          //  this->pincel->setPen(Qt::blue);
            pincel.drawLine(nx1,ny1, nx2,ny2);
        }
    }
}

void MyCanvasYX::mousePressEvent(QMouseEvent *event)
{
    if(this->pinto)
    {
        this->funcion->x0=x_funcion(event->x(), &this->size());
        this->funcion->y0=y_funcion(event->y(), &this->size());
        this->funcion->calcular();
        this->parentWidget()->parentWidget()->update();
    }
}
